package Filter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 黄忠
 * Created by 黄忠 on 2019-04-09.
 */
@WebFilter(filterName = "DgutFilter")
public class DgutFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
        res.setContentType("application/json");
        res.setCharacterEncoding("UTF-8");
        System.out.println(this.getClass());

        String token=req.getParameter("token");
        if(token==null) {
            //网页输入帐号密码登录：https://cas.dgut.edu.cn?appid=javaee
            //微型端网游授权登录：https://cas.dgut.edu.cn/wechat?state=javaee_*_ STAT
            //PC端微信扫码授权登录：https://cas.dgut.edu.cn/home/Wechat/qrLogin/state/ehall_*_admin.html
            res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee");
            System.out.println("登录");
        }
        else chain.doFilter(req,res);
    }
}
